
package Game;

import Animation.Die;
import Animation.Square;
import java.util.ArrayList;

/**
 * @author Kevin Tracy
 */
public class TurnManager {

    ArrayList<Player> playerList;
    ArrayList<Die> diceList;
    Dice dice;
    Board board;
    Square boardSquare;
    Player currentPlayer;
    private static  TurnManager turnManager;

    private  TurnManager()
    {
        playerList = new ArrayList<Player>();
        board = new Board();
        dice = new Dice();
        boardSquare = board.getBoardSquare();
        diceList = new ArrayList<Die>();
        diceList.add(new Die("dice", 10, 90, 80, 1));
        diceList.add(new Die("dice", 110, 90, 80, 1));
    }

    public static TurnManager getTurnManager()
    {
        if(turnManager == null)
        {
            turnManager = new TurnManager();
        }
        return turnManager;
    }

    public boolean isValidMove()
    {
        boolean result = false;
        result = isMoveInBounds();
        System.out.println(result);
        return result;
    }

    public void addPlayer(Player player)
    {
        playerList.add(player);
    }

    public ArrayList<Player> getPlayerList() {
        return playerList;
    }
    private boolean isMoveInBounds()
    {
        boolean result = false;
       
        if((currentPlayer.getDestXPos() > 30) && (currentPlayer.getDestYPos() > 30))
        {
            if((currentPlayer.getDestXPos() < boardSquare.getSize()) && (currentPlayer.getDestYPos() < boardSquare.getSize()))
            {
                result = true;
            }
        }

        return result;
    }
    public void makeMove()
    {
        if(isValidMove() && currentPlayer.getMovesRemaining() > 0)
        {
            currentPlayer.setCurrentX(currentPlayer.getDestXPos());
            currentPlayer.setCurrentY(currentPlayer.getDestYPos());
            currentPlayer.setMovesRemaining(currentPlayer.getMovesRemaining() -1); // in the case of a valid move, decrement the moves left

        }
        else
        {
            currentPlayer.setDestXPos(currentPlayer.getCurrentX());
            currentPlayer.setDestYPos(currentPlayer.getCurrentY());
        }
    }

    public void setCurrentPlayer(Player currentPlayer) {
        this.currentPlayer = currentPlayer;
    }

    public Player getCurrentPlayer() {
        return currentPlayer;
    }

    public void rollDice()
    {
        diceList = dice.rollDice(2, 6);
        int result = 0;
        for(int i = 0; i < diceList.size(); i++)
        {
            result += diceList.get(i).getNumber();
        }

        currentPlayer.setMoves(result);
    }

    public ArrayList<Die> getDiceList() {
        return diceList;
    }

    
    
    public Board getBoard()
    {
        return board;
    }

}